//
//  TranditionalShowCell.m
//  PersonalHospital
//
//  Created by qianfeng on 15/12/12.
//  Copyright (c) 2015年 QianFeng. All rights reserved.
//

#import "TranditionalShowCell.h"
#import "InfoModel.h"
#define Left_Gap 5

#define UP_Gap 10

@interface TranditionalShowCell ()

@property(nonatomic,strong)UILabel * headLable;

//@property(nonatomic,strong)UIButton * detail;

@property(nonatomic,strong)UIImageView * cureFilename;

@property(nonatomic,strong)UILabel * cureName;

@property(nonatomic,strong)UILabel * lineLable;

@property(nonatomic,strong)UILabel * cureDescribe;



@end
@implementation TranditionalShowCell


-(UILabel *)headLable{
    if (_headLable==nil) {
        _headLable=[[UILabel alloc]init];
        _headLable.frame=CGRectMake(0, 0, KScreen_Size.width, 40);
        _headLable.text=@"";
        _headLable.font=[UIFont systemFontOfSize:18];
        _headLable.backgroundColor=[UIColor colorWithRed:244/255.0 green:230/255.0 blue:201/255.0 alpha:1];
        _headLable.textAlignment=NSTextAlignmentCenter;
        _headLable.textColor=[UIColor blackColor];
    }
    return _headLable;
}

-(UIImageView *)cureFilename{
    if (_cureFilename==nil) {
        _cureFilename=[[UIImageView alloc]init];
        _cureFilename.frame=CGRectMake(0, 40, KScreen_Size.width,KTranditional_Scroll_Cell-40);
        _cureFilename.userInteractionEnabled=YES;
    }
    return _cureFilename;
}


//-(UIButton *)detail{
//    if (_detail==nil) {
//        _detail=[[UIButton alloc]init];
//        _detail.frame=CGRectMake(CGRectGetMaxX(_cureFilename.frame)-80,0, 40, 40);
//        _detail.backgroundColor=[UIColor colorWithRed:235/255.0 green:0 blue:72/255.0 alpha:1];
//        [_detail setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        [_detail setTitle:@"详情" forState:UIControlStateNormal];
//    }
//    return _detail;
//}

-(UILabel *)cureName{
    if (_cureName==nil) {
        _cureName=[[UILabel alloc]init];
        _cureName.frame=CGRectMake(Left_Gap, UP_Gap+40, 200, 20);
        _cureName.text=@"";
        _cureName.textAlignment=NSTextAlignmentLeft;
        _cureName.textColor=[UIColor blackColor];
        _cureName.font=[UIFont systemFontOfSize:18];
    }
    return _cureName;
}

-(UILabel *)lineLable{
    if (_lineLable==nil) {
        _lineLable=[[UILabel alloc]init];
        _lineLable.frame=CGRectMake(Left_Gap, CGRectGetMaxY(_cureName.frame)+1, 200, 1);
        _lineLable.backgroundColor=[UIColor grayColor];
        
    }
    return _lineLable;
}


-(UILabel *)cureDescribe{
    if (_cureDescribe==nil) {
        _cureDescribe=[[UILabel alloc]init];
        _cureDescribe.frame=CGRectMake(Left_Gap, CGRectGetMaxY(_lineLable.frame), 200, 20);
        _cureDescribe.text=@"";
        _cureDescribe.textAlignment=NSTextAlignmentLeft;
        _cureDescribe.textColor=[UIColor blackColor];
        _cureDescribe.font=[UIFont systemFontOfSize:14];
    }
    return _cureDescribe;
}


-(UIButton *)button{
    if (_button==nil) {
        _button=[[UIButton alloc]init];
        UIImage * image=[UIImage imageNamed:@"play-A"];
        _button.frame=CGRectMake((CGRectGetMaxX(_cureFilename.frame)-20)/2, (CGRectGetMaxY(_cureFilename.frame)-20)/2, 40, 40);
        [_button setBackgroundImage:image forState:UIControlStateNormal];
        [_button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}

-(void)buttonClick:(UIButton *)button{
    if (_buttonClick) {
        self.buttonClick();
    }
}

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addUI];
    }
    return self;
}

-(void)addUI{
    
    [self.contentView addSubview:self.headLable];
    
    [self.contentView addSubview:self.cureFilename];
    
 //   [self.cureFilename addSubview:self.detail];
    
    [self.contentView addSubview:self.button];
    
    [self.contentView addSubview:self.cureName];
    
    [self.contentView addSubview:self.lineLable];
    
    [self.contentView addSubview:self.cureDescribe];
}

-(void)setModel:(InfoModel *)model{
    if (model.cureDescribe.length>0) {
        NSString * wholeName=[model.cureDescribe componentsSeparatedByString:@"，"][0];
        NSString * name=[wholeName componentsSeparatedByString:@"缓解"][1];
        
        NSString * reallyName=[name componentsSeparatedByString:@"。"][0];
        
        self.headLable.text=reallyName;
    }
    _model=model;
    [self.cureFilename sd_setImageWithURL:[NSURL URLWithString:model.cureFilename]];
    self.cureName.text=model.cureName;
    self.cureDescribe.text=model.cureDescribe;
}





@end
